package com.dk.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dk.Dto.PartPower;
import com.dk.pojo.Menuandpart;
import com.dk.pojo.Part;
import com.dk.pojo.RESTFUL;
import com.dk.pojo.Users;
import com.dk.service.IMenuandpartService;
import com.dk.service.IPartService;
import com.dk.service.IPartanduserService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2022-07-08
 */
@RestController
@RequestMapping("/part")
public class PartController {
    @Autowired
    private IMenuandpartService menuandpartService;
    @Autowired
    private IPartService iPartService;

    @Autowired
    private IPartanduserService partanduserService;


    @ApiOperation(value = "删除角色")
    @GetMapping("delepart")
    public RESTFUL delePart(@ApiParam("删除的id") Integer id){

        iPartService.removeById(id);
        return new RESTFUL().SUCCESS();
    }
    @PostMapping("addpart")
    @ApiOperation(value = "增加角色")
    public RESTFUL addPart(@RequestBody Part part){
        iPartService.save(part);
        return new RESTFUL().SUCCESS();
    }
    @ApiOperation(value = "修改角色")
    @PostMapping("updatepart")
    public RESTFUL updatePart(@RequestBody Part part){
        iPartService.updateById(part);
        return new RESTFUL().SUCCESS();
    }
    @ApiOperation(value = "批量删除角色")
    @Transactional
    @PostMapping("delepartlsit")
    public RESTFUL delePartList(@RequestBody List<Integer> idList){

        iPartService.removeByIds(idList);
        partanduserService.deleIpart(idList);
        menuandpartService.deleIpart(idList);
        return new RESTFUL().SUCCESS();
    }

    @GetMapping("selepart")
    @ApiOperation(value = "查询角色")
    public RESTFUL selectBysome(
            @ApiParam("姓名") String name,
           @ApiParam("状态") String status,
            @ApiParam("页码") Integer ipage,
            @ApiParam("页容量") Integer size
    ){

        Page<Part> page=new Page<>(ipage,size);
        return new RESTFUL().SUCCESS(iPartService.getPartList(page,name,status));

    }




}
